const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
console.log('webpack---->>>prod', process.env.NODE_ENV)
module.exports = {
  mode: 'production',
  entry: {
    app: './src/app',
    ch: './src/main',
  },
  output: {
    path: path.resolve(__dirname, 'project'),
    filename: '[name]_[hash:6].js',
  },
  module: {
    rules: [
      { test: /\.vue$/, use: 'vue-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      {
        test: /\.jpg|png|gif|jpeg$/,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name]_[hash:3].[ext]',
            outputPath: 'img/',
          },
        },
      },
      {
        test: /\.ttf|eot|svg|woff|woff2$/,
        use: 'url-loader',
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      chunks: ['app'],
      title: 'app-h5',
    }),
    new CleanWebpackPlugin(),
    new VueLoaderPlugin(),
  ],
  devServer: {
    compress: true,
    port: 9000,
    proxy: {
        // '/api2': {
        //     target: 'http://localhost:8090',
        //     // 设置域名时必须加上
        //     changeOrigin: true,
        //     // 重写路径
        //     pathRewrite: {
        //     '^/api2': '',
        //     },
        //     secure: true,
        // },
        '/api': {
            target: 'http://101.132.173.21/',
            changeOrigin: true,
            pathRewrite: {
            '^/api': 'api',
            },
            cookieDomainRewrite: {
            '*': 'localhost',
            },
        },
    },
  },
};
